package leetcode.tree;

import leetcode.tree.common.TreeNode;

/**
 * @author mazouri
 * @create 2021-05-03 22:01
 */
public class _111_minDepth {
    public int minDepth(TreeNode root) {
        if (root == null) return 0;
        int left = minDepth(root.left);
        int right = minDepth(root.right);

        //既然left==null，那left一定为0
//        if (root.right == null || root.left == null) {
//            return left + right + 1;
//        }else {
//            return Math.min(left,right)+1;
//        }

        return root.right == null || root.left == null ? left + right + 1 : Math.min(left,right)+1;
    }
}
